#include "StdAfx.h"
#include "TrunkMapper.h"
#include "AnalogTrunk.h"

namespace DBLayer {

CTrunkMapper::~CTrunkMapper(void)
{
}

/*bool CTrunkMapper::loadData(int type,CTinyDBInterface* DBIF)
{
	m_DBType = type;
	m_DBIF = DBIF;
	m_MapperData.clear();
	if(type == DBTYPE_MYSQL)
	{
		try{
			sql::ResultSet * rs = (sql::ResultSet*)DBIF->executeSQL(std::string("SELECT trunknumber, trunkSeq FROM trunk")+m_filterStr );
			if(rs == NULL)
				return false;
			while (rs->next())
			{
				//process data
				std::string trunknumber = rs->getString("trunknumber");
				std::string trunkSeq = rs->getString("trunkSeq");
				std::map<std::string,std::string> tempMap;
				tempMap.insert(std::pair<std::string,std::string>("trunknumber",trunknumber));
				tempMap.insert(std::pair<std::string,std::string>("trunkSeq",trunkSeq));
				m_MapperData.push_back(tempMap);
			}
		}
		catch (sql::SQLException &e) {
			std::string err =  e.what();
			return false;
		}
	}

	return true;
}*/

std::vector<HAL::CTinyDevice*>* CTrunkMapper::GetAll()
{
	if(m_DBType == DBTYPE_MYSQL)
	{
		sql::ResultSet * rs = executeSql(selectStr);
		if(rs == NULL)
			return NULL;

		std::vector<HAL::CTinyDevice*>* devices = new std::vector<HAL::CTinyDevice*>();
		while(rs->next())
		{
			HAL::CAnalogTrunk * trunk = new HAL::CAnalogTrunk();
			trunk->extNumber = rs->getString("trunknumber");
			trunk->m_CardID = rs->getInt("cardid");
			trunk->m_ChannelID = rs->getInt("channelID");
			trunk->m_CardSN = rs->getString("cardsn");
			trunk->m_CardType = rs->getString("cardname");
			devices->push_back((HAL::CTinyDevice*)trunk);
		}
		return devices;
	}
	return NULL;
}
}
